package logic

import (
	"context"
	"store/models"

	"store/storerpc/internal/svc"
	"store/storerpc/storerpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type StoreListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewStoreListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StoreListLogic {
	return &StoreListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 门店列表
func (l *StoreListLogic) StoreList(in *storerpc.StoreListRequest) (*storerpc.StoreListResponse, error) {
	// todo: add your logic here and delete this line

	var stores []models.Store
	models.DB.Debug().Find(&stores)

	var StoresLists []*storerpc.StoreList
	for _, store := range stores {
		list := storerpc.StoreList{
			Name:    store.Name,
			Address: store.Address,
			StoreId: int64(store.ID),
			UserId:  store.UserId,
		}
		StoresLists = append(StoresLists, &list)
	}

	return &storerpc.StoreListResponse{
		List: StoresLists,
	}, nil
}
